#!/usr/bin/python

"""Unit tests for module words.py."""

import words
import unittest

class TestWordCount(unittest.TestCase):

  def testMakeDict(self):
    text_1 = 'Then a MAN, man, is a Man and it is so then when then then then maybe.'
    self.assertDictEqual({'then':5, 'a':2, 'man,':2, 'is':2, 'man':1,
      'and':1, 'it':1, 'so':1, 'when':1, 'maybe.':1},
      words.MakeDict(text_1))
    text_2 = ''
    self.assertDictEqual({}, words.MakeDict(text_2))
    text_3 = 'aleboaleboaleboaleboaleboaleboalebo'
    self.assertDictEqual({'aleboaleboaleboaleboaleboaleboalebo':1},
      words.MakeDict(text_3))
    text_4 = 'aha aha 4, 6 a 6 ano ANo k.'
    self.assertDictEqual({'aha':2, '4,':1, '6':2, 'a':1, 'ano':2,
      'k.':1}, words.MakeDict(text_4))
    text_5 = '.,.....,,,,--'
    self.assertDictEqual({'.,.....,,,,--':1}, words.MakeDict(text_5))

  def testCount(self):
    dict_1 = {'whey':3, 'aho':10, 'tom':1, 'sorry':5}
    self.assertEqual('\n aho : 10\n sorry : 5\n tom : 1\n whey : 3', words.Count(dict_1))
    dict_2 = {'takaleboaleboaleboalebo':4}
    self.assertEqual('\n takaleboaleboaleboalebo : 4', words.Count(dict_2))
    dict_3 = {}
    self.assertEqual('', words.Count(dict_3))
    dict_4 = {'same':2, 'aloha':10, '4':3, 'done':1, '11':2}
    self.assertEqual('\n 11 : 2\n 4 : 3\n aloha : 10\n done : 1\n same : 2', words.Count(dict_4))
    dict_5 = {'.,...,,,--':5}
    self.assertEqual('\n .,...,,,-- : 5', words.Count(dict_5))
    dict_6 = {(2,3):11}
    self.assertEqual('\n (2, 3) : 11', words.Count(dict_6))
# should I test case when there is dictionary inside dictionary?

  def testGetTheSecond(self):
    self.assertEqual(5, words.GetTheSecond(('aloha', 5)))

  def testTopcount(self):
    dict_1 = {'when':1, 'za':22, 'so':1, 'fe':21, 'maybe':1, 'fi':20, 'man-':1,
      'q':19, 'g.':1, 'r':18, 'is':3, 'fuf':17, 'man':4, 'uj':16, 'a':5,
      'kvi':15, 'du':6, 'so':14, 'lol':7, 'hu':13, 'it.':8, 'ow':12, 'and':9,
      'it':11, 'then':10}
    self.assertEqual('\n za : 22\n fe : 21\n fi : 20\n q : 19\n '
      'r : 18\n fuf : 17\n uj : 16\n kvi : 15\n so : 14\n hu : 13\n ow : 12\n '
      'it : 11\n then : 10\n and : 9\n it. : 8\n lol : 7\n du : 6\n a : 5\n '
      'man : 4\n is : 3', words.Topcount(dict_1))
    dict_2 = {'when':15, 'za':22, 'so':14, 'fe':21, 'maybe':13, 'fi':20, 'man-':12,
      'q':19, 'g.':11, 'r':18, 'is':10, 'fuf':17, 'man':9, 'uj':16, 'a':8}
    self.assertEqual('\n za : 22\n fe : 21\n fi : 20\n q : 19\n r : 18\n '
      'fuf : 17\n uj : 16\n when : 15\n so : 14\n maybe : 13\n man- : 12\n '
      'g. : 11\n is : 10\n man : 9\n a : 8', words.Topcount(dict_2))
    dict_3 = {'when':11}
    self.assertEqual('\n when : 11', words.Topcount(dict_3))
    dict_4 = {}
    self.assertEqual('', words.Topcount(dict_4))

  def testCheckFlags(self):
    self.assertTrue(words.CheckFlags(True, True, 'fake_filename'))
    self.assertFalse(words.CheckFlags(True, True, None))
    self.assertTrue(words.CheckFlags(True, False, 'fake_filename'))
    self.assertFalse(words.CheckFlags(True, False, None))
    self.assertTrue(words.CheckFlags(False, True, 'fake_filename'))
    self.assertFalse(words.CheckFlags(False, True, None))
    self.assertFalse(words.CheckFlags(False, False, 'fake_filename'))
    self.assertFalse(words.CheckFlags(False, False, None))


if __name__ == '__main__':
  unittest.main()
